package com.meida.common.enums;

import com.alibaba.fastjson.annotation.JSONType;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;

/**
 * 订单状态
 *
 * @author Administrator
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
@Getter
@JSONType(serializeEnumAsJavaBean = true)
public enum OrderStatusEnum {
    /**
     * 内置订单状态
     */
    UNPAY(1, "待付款"),
    UNDELIVERY(2, "待发货"),
    UNRECEIVE(3, "待收货"),
    UNCOMMENT(4, "待评价"),
    FINISHED(100, "已完成"),
    CLOSE(0, "已取消");
    public String text;

    public Integer code;

    OrderStatusEnum(Integer code, String text) {
        this.text = text;
        this.code = code;
    }

    OrderStatusEnum(Integer code) {
        this.text = getText(code);
        this.code = code;
    }


    public static String getText(Object code) {
        String v = "";
        for (OrderStatusEnum accountTypeEnum : values()) {
            if (accountTypeEnum.code.equals(code)) {
                v = accountTypeEnum.text;
                break;
            }
        }
        return v;
    }

    public static String getName(String code) {
        String v = "";
        for (OrderStatusEnum accountTypeEnum : values()) {
            if (accountTypeEnum.code.equals(code)) {
                v = accountTypeEnum.name();
                break;
            }
        }
        return v;
    }

    public static OrderStatusEnum getEnum(Integer code) {
        for (OrderStatusEnum accountTypeEnum : values()) {
            if (accountTypeEnum.code.equals(code)) {
                return accountTypeEnum;
            }
        }
        return null;
    }


}
